import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Scanner;

import processing.app.Preferences;


public class Main {
    static InputStream input;
    static OutputStream output;
    
    public static void main(String[] args) throws Exception{
        PrefsHack.init();
        System.out.println("Using port: " + Preferences.get("serial.port"));
        CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
                Preferences.get("serial.port"));
 
        SerialPort port = (SerialPort)portId.open("serial talk", 4000);
        input = port.getInputStream();
        BufferedReader bis = new BufferedReader(new InputStreamReader(input));
        output = port.getOutputStream();
        port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        
        
        CircleTest frame = new CircleTest();
        frame.setSize(900, 500);
        frame.setVisible(true);
        float x;
        float y;
        while(true){
            while(input.available()>0) {
                String st = bis.readLine() + "\n";
                Scanner s = new Scanner(st).useDelimiter("\\t");
                s.next();
                        x = new Float(s.next());
                        frame.x = (int)x;
                        System.out.print(x);
                        y = new Float(s.next());
                        frame.y = (int)y;
                        System.out.print(" ");
                        System.out.println(y);
                        System.out.println("\n");
               frame.repaint();
            }
        }
    }
}